<?php
namespace app\admin\controller;
use app\service\billService;
use app\service\communityService;
use app\service\propertyService;
use invoice\Api;
use think\facade\Db;
use think\facade\View;

class ZftBlackUser extends Common{
    public function index(){


        $data = request()->get();
        $where=array();
        if (!empty($data)){
            if(!empty($data['name'])){
                $where['name'] = array("like","%".$data['name']."%");//账单编号
            }
            if(!empty($data['user_id'])){
                $where[] = ["user_id","like","%".$data['user_id']."%"];

            }

        }
        //$where['a.property_id'] = array('in',$com['property_id']);

        $where = array_filter($where);
        $list =Db::name('zft_black_user')
                        ->where($where)
                        ->order('id','desc')
                        ->paginate(20);


        $number = Db::name('zft_black_user')->where($where)->count();
        View::assign('number',$number);


        View::assign('list', $list);
        View::assign('listRow',$list);
        foreach ($data as $k => $v) {
            View::assign($k, $v);
        }
        return View::fetch("list");
    }
    
    
    public function add(){
         //根据当前账号查询物业信息

        if(request()->isPost()){
            //获取表单数据
            $data = request()->post();
            $user=Db::table('zft_black_user')->where("user_id",$data["user_id"])->find();
            if(!empty($user)){
             return "改用户已经添加";
            }
            $data["create_time"]=date("Y-m-d H:i:s");
            //将数据插入数据库
            $result = Db::name('zft_black_user')->insert($data);
            //判断数据是否插入成功
            if($result){
                $this->success('添加成功',url('index'));
            }else{
                $this->error('添加失败',url('add'));
            }
        }else{
            return View::fetch('add');
        }
    }
    
    public function userDel(){
        $id = request()->param('id');
        $validate = $this->validate(request()->param(),[
            'id'	=>	'require|number'
        ]);
        if($validate !== true){
            $this->error($validate);
        }
        //判断是否存在该数据
        $info = Db::table('zft_black_user')->where("id",$id)->find();
        if(empty($info)){
            $this->error('该物业不存在');
        }
        $result = Db::table('zft_black_user')->delete($id);
        if($result){

            $this->success('删除用户成功',url('index'));
        }else{
            $this->error('删除用户失败',url('index'));
        }
    }
    



}